import { getDict } from "~/utils";
import uploadMedia from "@/components/upload-media";
import {
    inspectionList,
    getEditInformation,
    propertyNameList,
    useUnitList,
    getCheckItemList,
    changeModifyInspectionResults,
    deleteDeleteInspectionResults
} from "../../../api/check-in.js";

export default {
    components: { uploadMedia },
    provide () {
        return {
            initList: this.getListData
        };
    },
    data () {
        return {
            manageUnits: [],
            //首页表格勾选列表
            selectDataArr: [],
            inspectionResults: [],
            pager: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 10 // 每页显示多少条
            },
            loading: false,
            // 首页分页及条件查询依赖
            uploadFileList: [], // 选中文件列表
            searchDataFrom: {},
            title: "查看巡查结果",
            tabTitle: "上报隐患记录",
            projectType: "",
            dialogTableVisible: false,
            manageUnits: [],
            form: {
                name: "",
                region: "",
                date1: "",
                date2: "",
                delivery: false,
                type: [],
                resource: "",
                desc: ""
            },
            params: {
                current: 1,
                size: 10,
                propertyName: ""
            },
            // 过滤检索配置
            filterList: [
                {
                    label: "物业类型",
                    inputType: "dict",
                    name: "projectType",
                    dictName: "property_types",
                    multiple: true
                },
                {
                    label: "检查结果",
                    inputType: "dict",
                    name: "inspectionResult",
                    dictName: "inspection_result",
                    multiple: true
                },
                {
                    label: "管理所",
                    inputType: "dict",
                    name: "manageUnit",
                    dictName: "administrative_office",
                    multiple: true
                },
                {
                    label: "检查日期",
                    inputType: "daterange",
                    name: ["startDate", "endDate"]
                    // dictName: "inspection_result",
                }
            ],
            tableData: [],
            //新增|编辑表单数据
            resultDetailsForm: {
                reportDangerRecord: []
            }
        };
    },
    mounted () {
        this.getListData();
        this.manageUnits = getDict("administrative_office")
    },
    methods: {
        //  * 码值转换
        dictVal_propertyTypes (row, column, cellValue) {
            let obj = getDict("property_types").find(
                p => p.value == cellValue
            );
            return obj ? obj.label : ''
        },
        // 管理所格式化
        manageFormatter (row, column, cellValue) {
            const manage = getDict("administrative_office").find(
                item => item.value == cellValue
            );
            return manage.label || "";
        },
        //获取巡查结果列表
        getListData (params = {}) {
            let requestData = { ...this.params, ...params };
            inspectionList(requestData)
                .then(res => {
                    const { current, size, total, records } = res.data.data;
                    this.tableData = records;
                    this.params = requestData;
                    this.pager = { total, current, size };
                })
                .catch(() => { });
        },
        //关闭弹框
        close () {
            this.$refs.resultDetailsForm.resetFields();
        },
        showDetailsOfInspectionResults (v, row) {
            this.dialogTableVisible = true;
            getEditInformation(row.resultId)
                .then(res => {
                    // 给表单复制
                    this.resultDetailsForm = JSON.parse(
                        JSON.stringify(res.data.data)
                    );
                    if (
                        [
                            "新增巡查结果",
                            "编辑巡查结果",
                            "查看巡查结果"
                        ].includes(this.title)
                    ) {
                        this.$nextTick(() => {
                            this.$refs.upload &&
                                this.$refs.upload.getFiles(
                                    this.resultDetailsForm.resultId
                                );
                        });
                    }
                })
                .catch({});
        }
    }
};
